package com.example.dubboredisconsumer.controller;

import model.Student;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import service.StudentService;

@RestController
public class DemoController {
    @DubboReference(interfaceClass = StudentService.class,version="1.0")
    private StudentService studentService;

    @PostMapping("/add")
    public String addStudent(Student student){
        int result=studentService.addStudent(student);
        String msg="请稍后处理";
        if(result==1){
            msg="success";
        }else if(result==2){
            msg="has been registered";
        }else if(result==3){
            msg="no phone";
        }
        return msg;
    }

    @GetMapping("/query")
    public String queryStudent(Integer id){
        String msg="";
        Student student=null;
        if(id!=null&id>0){
            student=studentService.queryStudent(id);
            if (student!=null){
                msg="message:"+student;
            }else {
                msg="nothing";
            }
        }else {
            msg="id error";
        }
        return msg;
    }
}
